import { defineStore } from 'pinia';
import {ref} from "vue";

export const useAuthStore = defineStore('auth', ()=>{

  const token = ref<string | null>(null)
  const uid = ref<number | null>(null)
  const username = ref<string | null>()

  function setToken(t: string) {
    token.value = t;
  }
  function clearToken() {
    token.value = null;
    uid.value = null
  }

  function setUid(u:number){
    uid.value = u
  }

  function setUsername(u:string){
    username.value = u
  }

  return {
    setToken,clearToken,token,uid,setUid,username,setUsername
  }
},{
  persist: {
    enabled: true,  // 启用持久化
    strategies: [
      {
        key: 'counter-store',  // 本地存储的键名
        storage: localStorage, // 使用 localStorage
      },
    ],
  },
});
